package top.yj95.xiets.panel;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JSplitPane;
import javax.swing.WindowConstants;

/**
 * 文章《<a href="https://blog.csdn.net/xietansheng/article/details/74366517" target="_balnk">JavaSwing_3.3: JSplitPane（分隔面板）</a>》中的示例代码
 * @author 杨军
 * @since 2023-12-26
 */
public class JSplitPaneDemo {

    public static void main(String[] args) {
        JFrame frame = new JFrame("测试窗口");
        frame.setSize(300, 300);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        
        // 创建分隔面板
        JSplitPane splitPanel = new JSplitPane();
        
        // 设置左右两边显示的组件
        splitPanel.setLeftComponent(new JButton("左边按钮"));
        splitPanel.setRightComponent(new JButton("右边按钮"));
        
        // 分隔条上显示快速 折叠/展开 两边组件的小按钮
        splitPanel.setOneTouchExpandable(true);
        
        // 拖动分隔条时连续重绘组件
        splitPanel.setContinuousLayout(true);
        
        // 设置分隔条的初始位置
        splitPanel.setDividerLocation(150);
        
        // 把分隔面板作为内容面板添加到窗口并显示
        frame.setContentPane(splitPanel);
        frame.setVisible(true);
    }
    
}
